Skip to content

Add wp db status command for database health overview#307

Open
Copilot wants to merge 14 commits intomainfrom
copilot/add-wp-db-status-command
Open

Add wp db status command for database health overview#307
Copilot wants to merge 14 commits intomainfrom
copilot/add-wp-db-status-command

Conversation

Copy link
Contributor

Copilot AI commented Feb 1, 2026

Adds a new wp db status command that provides a consolidated view of database health and configuration information in a single command, eliminating the need to run multiple separate database commands (wp db size, wp db tables, wp db prefix, wp db check).

Implementation

  • New status() method in DB_Command class that works without loading WordPress

    • Uses raw SQL queries via self::run() method instead of $wpdb for database information
    • Queries information_schema.TABLES for table count, size, engine, charset, and collation
    • Gets table prefix from global $table_prefix variable (wp-config.php)
    • Runs mysqlcheck for health status
    • Detects mixed engines/charsets/collations across tables
    • Formats output as aligned key-value pairs using data-driven approach
    • Supports --dbuser, --dbpass, and --defaults options for authentication
  • Command registration in composer.json

  • Comprehensive Behat test coverage with regex matching for dynamic values and credential option testing

Key Features

  • Works without loading WordPress: Operates at after_wp_config_load level (class default), similar to wp db query
  • Functions before WordPress installation: Provides database diagnostics even when WordPress is not fully installed
  • No WordPress dependencies: Uses raw SQL queries through mysql client instead of $wpdb object
  • Proper SQL escaping: Uses addslashes() with LIKE pattern escaping for security
  • Handles edge cases: NULL values, mixed configurations, empty databases, zero table count

Output Example

Database Name:     wp_cli_test
Tables:            54
Total Size:        312 KB
Prefix:            wp_
Engine:            InnoDB
Charset:           utf8mb4
Collation:         utf8mb4_unicode_ci
Check Status:      OK

Notes

  • Uses SI units (1000-based) for size formatting, matching existing wp db size --human-readable behavior
  • Detects and displays "Mixed" when tables have different engines, charsets, or collations
  • Suitable for automation scripts and diagnostic tools that run before WordPress initialization
  • Maintains consistency with other database commands in credential handling
Original prompt

This section details on the original issue you should resolve

<issue_title>Add wp db status command for quick database health overview</issue_title>
<issue_description>I would like to suggesta new WP-CLI command: wp db status

The command would provide a concise, read-only overview of the current WordPress database health and configuration in a single output, reducing the need to run multiple separate commands.

For support, debugging, and hosting diagnostics, it would be beneficial to have a single, non-destructive command that aggregates key database information into one quick report.

Currently, checking database status requires running several commands such as: wp db size, wp db tables, wp db prefix, wp db check, etc.

My Proposed Command:

wp db status

Output Example:

Database Name:     wp_mehrazmorshed
Tables:            54
Total Size:        312 MB
Prefix:            wp_
Engine:            InnoDB
Charset:           utf8mb4
Collation:         utf8mb4_unicode_ci
Check Status:      OK
```</issue_description>

## Comments on the Issue (you are @copilot in this section)

<comments>
<comment_new><author>@ernilambar</author><body>
It will be included in next "3.0.0" version.</body></comment_new>
<comment_new><author>@swissspidy</author><body>
Yeah you can already try it out in the nightly release.

One difference is that the site-health command involves loading WordPress, whereas the db commands usually also work when WordPress is not even installed yet.</body></comment_new>
<comment_new><author>@ernilambar</author><body>
Although database info is available from "site-health" command I am positive is adding specific db command which gives info without loading whole WordPress. It would be helpful in scripting.</body></comment_new>
</comments>


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits February 1, 2026 16:10
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Copilot AI changed the title [WIP] Add wp db status command for database health overview Add wp db status command for database health overview Feb 1, 2026
Copilot AI requested a review from swissspidy February 1, 2026 16:13
@codecov
Copy link

codecov bot commented Feb 1, 2026

Codecov Report

❌ Patch coverage is 98.03922% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/DB_Command.php 98.03% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@swissspidy swissspidy requested a review from Copilot February 2, 2026 01:50
@swissspidy

This comment was marked as resolved.

gemini-code-assist[bot]

This comment was marked as resolved.

This comment was marked as resolved.

swissspidy and others added 3 commits February 2, 2026 20:47
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
@swissspidy

This comment was marked as resolved.

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>

This comment was marked as resolved.

@swissspidy swissspidy marked this pull request as ready for review February 4, 2026 03:12
@swissspidy swissspidy requested a review from a team as a code owner February 4, 2026 03:12
@swissspidy

This comment was marked as resolved.

Copilot AI and others added 2 commits February 26, 2026 09:45
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>

This comment was marked as resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add wp db status command for quick database health overview

3 participants